#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include<string.h>
#include<stdbool.h>

bool is_pal(char* m, int len)
{
    int left = 0;
    int right = len - 1;
    while (left < right)
    {
        if (m[left++] != m[right--])
        {
            return false;
        }
    }
    return true;
}

int getChartoint(char x)
{
    int y = 0;
    if (x >= 'A' && x <= 'F')
    {
        y = x - 'A' + 10;
    }
    if (x >= '0' && x <= '9')
    {
        y = x - '0';
    }
    return y;
}
char inttoc(int x)
{
    if (x < 10)
    {
        return x + '0';
    }
    else
    {
        return x - 10 + 'A';
    }
}
void add(char* m, int n, int len)
{
    int i = 0, jw = 0;
    char sum[200] = { 0 };
    int left = 0;
    int right = len - 1;
    int end = len - 1;
    while (end >= 0)
    {
        int x = getChartoint(m[left++]);
        int y = getChartoint(m[right--]);
        int s = x + y;
        sum[i++] = inttoc((s + jw) % n);
        jw = (s + jw) / n;
        end--;
    }
    while (jw > 0)
    {
        sum[i] = inttoc(jw % n);
        jw /= n;
        i++;
    }
    strcpy(m, sum);
}
int main() {
    int n;
    scanf("%d", &n);
    char m[200] = { 0 };
    getchar();
    scanf("%s", m);
    int len = strlen(m);
    if (is_pal(m, len))
    {
        printf("STEP=%d", 1);
        return 1;
    }
    int count = 0;
    while (!is_pal(m, len))
    {
        add(m, n, len);
        len = strlen(m);
        count++;

        if (count >= 30)
        {
            printf("Impossible!\n");
            return 1;
        }
    }
    printf("STEP=%d", count);
    return 0;
}